<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
            <el-form-item label="姓名" prop="name">
                <el-input
                        v-model="queryParams.name"
                        placeholder="请输入姓名"
                        clearable
                        size="small"
                        @keyup.enter.native="handleQuery"
                />
            </el-form-item>
            <el-form-item label="性别" prop="sex">
                <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small">
                    <el-option label="请选择字典生成" value=""/>
                </el-select>
            </el-form-item>
            <el-form-item label="状态" prop="status">
                <el-select v-model="queryParams.status" placeholder="请选择状态 1、正常 2、离队" clearable size="small">
                    <el-option label="请选择字典生成" value=""/>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button
                        type="primary"
                        icon="el-icon-plus"
                        size="mini"
                        @click="handleAdd"
                        v-hasPermi="['training:sportsman:add']"
                >新增
                </el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button
                        type="danger"
                        icon="el-icon-delete"
                        size="mini"
                        :disabled="multiple"
                        @click="handleDelete"
                        v-hasPermi="['training:sportsman:remove']"
                >删除
                </el-button>
            </el-col>
        </el-row>

        <el-table v-loading="loading" :data="sportsmanList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center"/>
            <el-table-column label="PK" align="center" prop="id"/>
            <el-table-column label="姓名" align="center" prop="name"/>
            <el-table-column label="性别" align="center" prop="sex"/>
            <el-table-column label="出生日期" align="center" prop="birthday" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <!-- <el-table-column label="身高" align="center" prop="height" />
             <el-table-column label="体重" align="center" prop="weight" />
             <el-table-column label="坐高" align="center" prop="sitHigh" />
             <el-table-column label="臂展" align="center" prop="armSpread" />
             <el-table-column label="肩宽" align="center" prop="shoulderWidth" />
             <el-table-column label="腿长" align="center" prop="legLength" />
             <el-table-column label="小腿长" align="center" prop="tinyLegLength" />
             <el-table-column label="胸围" align="center" prop="bust" />
             <el-table-column label="臀围" align="center" prop="hipline" />
             <el-table-column label="腰围" align="center" prop="waistline" />-->
            <el-table-column label="参训时间" align="center" prop="trainingTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.trainingTime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="技术等级" align="center" prop="level"/>
            <!--      <el-table-column label="技术等级授予单位" align="center" prop="ratingUnit" />-->
            <el-table-column label="输送单位" align="center" prop="conveyingUnit"/>
            <el-table-column label="创建时间" align="center" prop="ctime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.ctime, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <!--      <el-table-column label="更新时间" align="center" prop="ltime" width="180">-->
            <!--        <template slot-scope="scope">-->
            <!--          <span>{{ parseTime(scope.row.ltime, '{y}-{m}-{d}') }}</span>-->
            <!--        </template>-->
            <!--      </el-table-column>-->
            <!--      <el-table-column label="部门ID" align="center" prop="deptid" />-->
            <!--      <el-table-column label="头像地址" align="center" prop="imgUrl" />-->
            <el-table-column label="状态" align="center" prop="status"/>
            <!--      <el-table-column label="学历" align="center" prop="education" />-->
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-edit"
                            @click="handleUpdate(scope.row)"
                            v-hasPermi="['training:sportsman:edit']"
                    >修改
                    </el-button>
                    <el-button
                            size="mini"
                            type="text"
                            icon="el-icon-delete"
                            @click="handleDelete(scope.row)"
                            v-hasPermi="['training:sportsman:remove']"
                    >删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
        />

        <!-- 添加或修改sportsman对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
            <el-form ref="form" :model="form" :rules="rules" label-width="90px">
                <el-col :span="12">
                    <el-form-item label="姓名" prop="name">
                        <el-input v-model="form.name" placeholder="请输入姓名"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="性别">
                        <el-select v-model="form.sex" placeholder="请选择性别">
                            <el-option label="请选择字典生成" value=""/>
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="出生日期" prop="birthday">
                        <el-date-picker clearable size="small" style="width: 200px"
                                        v-model="form.birthday"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        placeholder="选择出生日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
              <el-col :span="12">
                <el-form-item label="参训时间" prop="trainingTime">
                  <el-date-picker clearable size="small" style="width: 200px"
                                  v-model="form.trainingTime"
                                  type="date"
                                  value-format="yyyy-MM-dd"
                                  placeholder="选择参训时间">
                  </el-date-picker>
                </el-form-item>
              </el-col>
                <el-col :span="12">
                    <el-form-item label="身高" prop="height">
                        <el-input v-model="form.height" placeholder="请输入身高"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="体重" prop="weight">
                        <el-input v-model="form.weight" placeholder="请输入体重"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="坐高" prop="sitHigh">
                        <el-input v-model="form.sitHigh" placeholder="请输入坐高"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="臂展" prop="armSpread">
                        <el-input v-model="form.armSpread" placeholder="请输入臂展"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="肩宽" prop="shoulderWidth">
                        <el-input v-model="form.shoulderWidth" placeholder="请输入肩宽"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="腿长" prop="legLength">
                        <el-input v-model="form.legLength" placeholder="请输入腿长"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="小腿长" prop="tinyLegLength">
                        <el-input v-model="form.tinyLegLength" placeholder="请输入小腿长"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="胸围" prop="bust">
                        <el-input v-model="form.bust" placeholder="请输入胸围"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="臀围" prop="hipline">
                        <el-input v-model="form.hipline" placeholder="请输入臀围"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="腰围" prop="waistline">
                        <el-input v-model="form.waistline" placeholder="请输入腰围"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="技术等级" prop="level">
                        <el-input v-model="form.level" placeholder="请输入技术等级"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="授予单位" prop="ratingUnit">
                        <el-input v-model="form.ratingUnit" placeholder="请输入技术等级授予单位"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="输送单位" prop="conveyingUnit">
                        <el-input v-model="form.conveyingUnit" placeholder="请输入输送单位"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="部门ID" prop="deptid">
                        <el-input v-model="form.deptid" placeholder="请输入部门ID"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="头像地址" prop="imgUrl">
                        <el-input v-model="form.imgUrl" placeholder="请输入头像地址"/>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="状态">
                        <el-radio-group v-model="form.status">
                            <el-radio label="1">请选择字典生成</el-radio>
                        </el-radio-group>
                    </el-form-item>
                </el-col>
                <el-col :span="12">
                    <el-form-item label="学历" prop="education">
                        <el-input v-model="form.education" placeholder="请输入学历"/>
                    </el-form-item>
                </el-col>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {
        listSportsman,
        getSportsman,
        delSportsman,
        addSportsman,
        updateSportsman,
        exportSportsman
    } from "@/api/training/sportsman";

    export default {
        name: "Sportsman",
        data() {
            return {
                // 遮罩层
                loading: true,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 总条数
                total: 0,
                // sportsman表格数据
                sportsmanList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    name: undefined,
                    sex: undefined,
                    birthday: undefined,
                    height: undefined,
                    weight: undefined,
                    sitHigh: undefined,
                    armSpread: undefined,
                    shoulderWidth: undefined,
                    legLength: undefined,
                    tinyLegLength: undefined,
                    bust: undefined,
                    hipline: undefined,
                    waistline: undefined,
                    trainingTime: undefined,
                    level: undefined,
                    ratingUnit: undefined,
                    conveyingUnit: undefined,
                    ctime: undefined,
                    ltime: undefined,
                    deptid: undefined,
                    imgUrl: undefined,
                    status: undefined,
                    education: undefined
                },
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                    name: [
                        {required: true, message: "姓名不能为空", trigger: "blur"}
                    ],
                    sex: [
                        {required: true, message: "性别不能为空", trigger: "blur"}
                    ],
                }
            };
        },
        created() {
            this.getList();
        },
        methods: {
            /** 查询sportsman列表 */
            getList() {
                this.loading = true;
                listSportsman(this.queryParams).then(response => {
                    this.sportsmanList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    name: undefined,
                    sex: undefined,
                    birthday: undefined,
                    height: undefined,
                    weight: undefined,
                    sitHigh: undefined,
                    armSpread: undefined,
                    shoulderWidth: undefined,
                    legLength: undefined,
                    tinyLegLength: undefined,
                    bust: undefined,
                    hipline: undefined,
                    waistline: undefined,
                    trainingTime: undefined,
                    level: undefined,
                    ratingUnit: undefined,
                    conveyingUnit: undefined,
                    ctime: undefined,
                    ltime: undefined,
                    deptid: undefined,
                    imgUrl: undefined,
                    status: "0",
                    education: undefined
                };
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id)
                this.single = selection.length != 1
                this.multiple = !selection.length
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加sportsman";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids
                getSportsman(id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改sportsman";
                });
            },
            /** 提交按钮 */
            submitForm: function () {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != undefined) {
                            updateSportsman(this.form).then(response => {
                                if (response.code === 200) {
                                    this.msgSuccess("修改成功");
                                    this.open = false;
                                    this.getList();
                                } else {
                                    this.msgError(response.msg);
                                }
                            });
                        } else {
                            addSportsman(this.form).then(response => {
                                if (response.code === 200) {
                                    this.msgSuccess("新增成功");
                                    this.open = false;
                                    this.getList();
                                } else {
                                    this.msgError(response.msg);
                                }
                            });
                        }
                    }
                });
            },
            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                this.$confirm('是否确认删除sportsman编号为"' + ids + '"的数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function () {
                    return delSportsman(ids);
                }).then(() => {
                    this.getList();
                    this.msgSuccess("删除成功");
                }).catch(function () {
                });
            },
            /** 导出按钮操作 */
            handleExport() {
                const queryParams = this.queryParams;
                this.$confirm('是否确认导出所有sportsman数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(function () {
                    return exportSportsman(queryParams);
                }).then(response => {
                    this.download(response.msg);
                }).catch(function () {
                });
            }
        }
    };
</script>